package com.glc.gao.gavin.rxjavademo.operator;

import android.view.View;

import com.glc.gao.gavin.rxjavademo.R;

import io.reactivex.Observable;
import io.reactivex.functions.BiFunction;
import io.reactivex.functions.Consumer;

public class ReduceActivity extends BaseActivity {
    @Override
    public int getDescribeText() {
        return R.string.describe_reduce;
    }

    @Override
    protected int getContextView() {
        return R.layout.activity_reduce;
    }

    public void executeReduce(View view) {
        Observable.just(1, 2, 3).reduce(new BiFunction<Integer, Integer, Integer>() {
            @Override
            public Integer apply(Integer integer, Integer integer2) throws Exception {
                return integer + integer2;
            }
        }).subscribe(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) throws Exception {

                print("reduce结果: " + integer);
            }
        });
    }
}
